import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
import Login from '@/components/login/Login'
import SourceManage from '@/components/SourceManage'
import SqlSearch from '@/components/dataSearch/SqlSearch'
//全屏展示
import SqlSearchFull from '@/components/dataSearch/SqlSearchFull'
import SqlTaskList from '@/components/dataSearch/SqlTaskList'
import PostAPI from '@/components/APIManage/PostAPI'
import APIList from '@/components/APIManage/APIList/APIList'
import TestAPI from '@/components/APIManage/APIList/TestAPI'
import ViewAPI from '@/components/APIManage/APIList/ViewAPI'
import CallStatistics from '@/components/APIManage/APIList/CallStatistics'
import KeyManage from '@/components/APIManage/KeyManage'
import CreateKey from '@/components/APIManage/CreateKey'
//数据分析
import DataAnalysis from '@/components/DataAnalysis'
import OperationLog from '@/components/logAudit/OperationLog'
import LinkAccessLog from '@/components/logAudit/LinkAccessLog'
import User from '@/components/systemManage/User'
import SetUp from '@/components/systemManage/SetUp'
import FindPassword from '@/components/login/FindPassword'
import FindPassword2 from '@/components/login/FindPassword2'
import ChangePassword from '@/components/ChangePassword'

//数据探索功能
import dataExplore from '@/components/dataSearch/dataExplorePage/dataExplore'
import dataDimension from '@/components/dataSearch/dataExplorePage/dataDimension'
import echart from '@/components/dataSearch/dataExplorePage/echart'
import showIcon from '@/components/dataSearch/dataExplorePage/displayIcon'
// 以上随后修改，路由懒加载配置

Vue.use(Router)

const router = new Router({
  routes: [

    {
      path: '/',
      component: Login,
      name: 'Login'
    },
    {
      path: '/login',
      component: Login,
      name: 'Login'
    },
    {
      path: '/findPassword',
      component: FindPassword,
      name: 'FindPassword'
    },
    {
      path: '/findPassword2',
      component: FindPassword2,
      name: 'FindPassword2'
    },
    //全屏展示
    {
      path: '/sqlSearchFull',
      component: SqlSearchFull,
      name: 'SqlSearchFull'
    },

    {
      path: '/home',
      component: Home,
      name: 'Home',
      children: [
        {
          path: '/',
          name: 'SourceManage',
          component: SourceManage
        },
        {
          path: '/sourceManage',
          name: 'SourceManage',
          component: SourceManage
        },
        {
          path: '/sqlSearch',
          name: 'SqlSearch',
          component: SqlSearch
        },
        {
          path: '/sqlTaskList',
          name: 'SqlTaskList',
          component: SqlTaskList
        },
        {
          path: '/postAPI',
          name: 'PostAPI',
          component: PostAPI
        },
        {
          path: '/APIList',
          name: 'APIList',
          component: APIList
        },
        {
          path: '/testAPI/:id',
          name: 'TestAPI',
          component: TestAPI
        },
        {
          path: '/viewAPI/:id/:status',
          name: 'ViewAPI',
          component: ViewAPI
        },
        {
          path: '/callStatistics',
          name: 'CallStatistics',
          component: CallStatistics
        },
        {
          path: '/keyManage',
          name: 'KeyManage',
          component: KeyManage
        },
        {
          path: '/createKey',
          name: 'CreateKey',
          component: CreateKey
        },
        //数据分析
        {
          path: '/dataAnalysis',
          name: 'DataAnalysis',
          component: DataAnalysis
        },
        {
          path: '/operationLog',
          name: 'OperationLog',
          component: OperationLog
        },
        {
          path: '/linkAccessLog',
          name: 'LinkAccessLog',
          component: LinkAccessLog
        },
        {
          path: '/user',
          name: 'User',
          component: User
        },
        {
          path: '/setUp',
          name: 'SetUp',
          component: SetUp
        },
        {
          path: '/changePassword',
          name: 'ChangePassword',
          component: ChangePassword
        },
        /*---数据探索页面开始 start---*/
        {
          path: '/dataExplore',
          component: dataExplore,
          name: 'dataExplore'
        },
        /*---数据探索页面开始 end---*/
        /*---图例字段映射 start---*/
        {
          path: '/dataDimension',
          component: dataDimension,
          name: 'dataDimension'
        },
        /*---图例字段映射 start---*/
        /*---选择图表页面 start---*/
        {
          path: '/echart',
          component: echart,
          name: 'echart'
        },
        /*---选择图表页面 start---*/
        /*---展示图表页面 start---*/
        {
          path: '/showIcon',
          component: showIcon,
          name: 'showIcon'
        }
        /*---展示图表页面 start---*/
        
      ]

    }
    


  ]
})

//导航守卫，使用router.beforeEach 注册一个全局前置守卫，判断用户是否登录
router.beforeEach((to, from, next) => {
  if(to.path === '/login' || to.path === '/' ){
    console.log("请登录");
    next();
  }
  else{
    let token = localStorage.getItem('Authorization');
    if(token === null || token === ''){
      console.log("没有登录");
      next('/login');
    }else{
      //console.log("登录成功");
      next();
    }
  }
});

export default router;



// export default new Router({
//   routes: [

//     {
//       path: '/',
//       component: Login,
//       name: ''
//     },
//     {
//       path: '/login',
//       component: Login,
//       name: ''
//     },
//     {
//       path: '/findPassword',
//       component: FindPassword,
//       name: 'FindPassword'
//     },
//     {
//       path: '/findPassword2',
//       component: FindPassword2,
//       name: 'FindPassword2'
//     },

//     {
//       path: '/home',
//       component: Home,
//       name: 'Home',
//       children: [{
//           path: '/',
//           name: 'Dashboard',
//           component: Dashboard
//         },
//         {
//           path: '/questionList',
//           name: 'QuestionList',
//           component: QuestionList
//         },
//         {
//           path: '/websiteManage',
//           name: 'WebsiteManage',
//           component: WebsiteManage
//         },
//         {
//           path: '/dashboard',
//           name: 'Dashboard',
//           component: Dashboard
//         },
//         {
//           path: '/addWebsite',
//           name: 'AddWebsite',
//           component: AddWebsite
//         },
//         {
//           path: '/history',
//           name: 'History',
//           component: History
//         },
//         {
//           path: '/location',
//           name: 'Location',
//           component: Location
//         },
//         {
//           path: '/message',
//           name: 'Message',
//           component: Message
//         },
//         {
//           path: '/search',
//           name: 'Search',
//           component: Search
//         },
//         {
//           path: '/user',
//           name: 'User',
//           component: User
//         },
//         {
//           path: '/addUser',
//           name: 'AddUser',
//           component: AddUser
//         },
//         {
//           path: '/editUser',
//           name: 'EditUser',
//           component: EditUser
//         },
//         {
//           path: '/system',
//           name: 'System',
//           component: System
//         },
//         {
//           path: '/helloWorld',
//           name: 'HelloWorld',
//           component: HelloWorld
//         }
//       ]

//     }
    


//   ]
// });


